package org.dromara.system.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.SysBuildingRoomBo;
import org.dromara.system.domain.vo.SysBuildingRoomVo;
import org.dromara.system.service.ISysBuildingRoomService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 房屋管理
 *
 * @author LSL
 * @date 2024-05-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/buildingRoom")
public class SysBuildingRoomController extends BaseController {

    private final ISysBuildingRoomService sysBuildingRoomService;

    /**
     * 查询房屋管理列表
     */
    @SaCheckPermission("system:buildingRoom:list")
    @GetMapping("/list")
    public TableDataInfo<SysBuildingRoomVo> list(SysBuildingRoomBo bo, PageQuery pageQuery) {
        return sysBuildingRoomService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出房屋管理列表
     */
    @SaCheckPermission("system:buildingRoom:export")
    @Log(title = "房屋管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysBuildingRoomBo bo, HttpServletResponse response) {
        List<SysBuildingRoomVo> list = sysBuildingRoomService.queryList(bo);
        ExcelUtil.exportExcel(list, "房屋管理", SysBuildingRoomVo.class, response);
    }

    /**
     * 获取房屋管理详细信息
     *
     * @param roomId 主键
     */
    @SaCheckPermission("system:buildingRoom:query")
    @GetMapping("/{roomId}")
    public R<SysBuildingRoomVo> getInfo(@NotNull(message = "主键不能为空")
                                            @PathVariable Long roomId) {
        return R.ok(sysBuildingRoomService.queryById(roomId));
    }

    /**
     * 新增房屋管理
     */
    @SaCheckPermission("system:buildingRoom:add")
    @Log(title = "房屋管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysBuildingRoomBo bo) {
        return toAjax(sysBuildingRoomService.insertByBo(bo));
    }

    /**
     * 修改房屋管理
     */
    @SaCheckPermission("system:buildingRoom:edit")
    @Log(title = "房屋管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysBuildingRoomBo bo) {
        return toAjax(sysBuildingRoomService.updateByBo(bo));
    }

    /**
     * 删除房屋管理
     *
     * @param roomIds 主键串
     */
    @SaCheckPermission("system:buildingRoom:remove")
    @Log(title = "房屋管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{roomIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                              @PathVariable Long[] roomIds) {
        return toAjax(sysBuildingRoomService.deleteWithValidByIds(List.of(roomIds), true));
    }
}
